package com.scy.java.io.input;

import java.io.FileInputStream;
import java.io.IOException;

//读取字节数据
public class FileInputStreamRead {
    public static void main(String[] args)  {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream("d:/test.txt");
            //读取数据，返回一个字节
//            int read = fis.read();
//            System.out.println((char)read);
//            read = fis.read();
//            System.out.println((char)read);
//            read = fis.read();
//            System.out.println((char)read);
//            read = fis.read();
//            System.out.println((char)read);
            //循环读取数据
            //定义变量保存数据
            int b;
            while ((b =fis.read()) != -1){
                System.out.print((char)b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    //关闭资源
                    fis.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

    }
}
